﻿//=======================================================================================
//
// Copyright (C) 2010-2011 Asia-Peak Technologies, Inc. All Rights Reserved.
// 
// All the code, text, graphics, media, design, programs and other works are
// protected by copyright law. Unauthorized reproduction or redistribution of them, 
// or any portion of them, are forbidden.
// 
//=======================================================================================
/****************************************************************************************
 * 
 * 文件说明：
 * 
 * 作者：陈家龙
 * 创始时间：2011/6/16 16:22:05
 * 创建说明：
 * 
 * 修改人:
 * 修改时间：
 * 修改说明：
 * 
 * 修改人：
 * 修改时间：
 * 修改说明：
 *    
****************************************************************************************/
using System.Web.UI.WebControls;
using System.Web.UI;

namespace CSP.Common.Web
{
    /// <summary>
    /// 针对table
    /// </summary>
    public class EmptyRepeaterInfo : Literal
    {
        public EmptyRepeaterInfo()
        {
            this.EnableViewState = false;
        }

        public int Colspan
        {
            get;
            set;
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            Repeater repeater = this.GetRepeater(this.Parent);
            if (repeater == null)
            {
                base.Render(writer);
            }
            else
            {
                if (repeater.Items.Count == 0)
                    writer.Write("<tr><td colspan=\"{0}\">{1}</td></tr>", this.Colspan, this.Text);
            }
        }

        Repeater GetRepeater(Control parent)
        {
            if (parent == null)
                return null;
            Repeater repeater = parent as Repeater;
            if (repeater == null)
            {
                return this.GetRepeater(parent.Parent);
            }
            else
            {
                return repeater;
            }
        }
    }
}
